package com.foton.springbootdemo.listern;

import com.foton.springbootdemo.entity.UserCustom;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * @Author RenPu
 * @Date 2023/3/24 16:32
 * @Version 1.0
 * @Description: 编写事件监听机制
 **/

@Slf4j
@Component
public class CustomListen implements ApplicationListener<ContextRefreshedEvent> {

    @Value("${names}")
    private String name;

    @Autowired
    private UserCustom userCustom;



    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.info("加载到从SpringApplication中设置的配置参数：{}",name);
        log.info("加载到从@ConfigurationProperties设置的配置参数：{}",userCustom.getUserName());
    }
}
